import $ from '../common';
Page({
  data: {
    titleHeight: $.gData().titleHeight,
    statuHeight: $.gData().statuHeight,
    countdown: 30,
  },

  // 签到
  getIdentify(obj) {
    $.post('/teacher/sign/add', obj, res => {
      $.navigateTo(`/Signin/signresult?ner=${JSON.stringify(res)}`)
    }, fail => {
      $.navigateTo(`/Signin/signresult?ner=${JSON.stringify(fail)}`)
    })
  },


  onLoad(e) {    
    let countdown = this.data.countdown
    let _fn = () => {
      if (countdown == 0) {
        this.resetDentify()
      } else {
        this.setData({
          countdown: countdown,
        })
        if (countdown == 30) {
          this.getIdentify(JSON.parse(e.obj))
        }
        countdown--
      }
    }
    _fn()
    this.setTimeDentify = setInterval(() => {
      _fn()
    }, 1000)
  },

  resetDentify() { //倒计时到期时
    clearInterval(this.setTimeDentify)
    this.setData({
      countdown: 0,
    })
  },
  onShow() {},
})